<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\helpers\ArrayHelper;

/* @var $this yii\web\View */
/* @var $model app\models\GkyWeMenu */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="wechat-menu-form">

    <?php $form = ActiveForm::begin(); ?>

    <?php
        $menus = \app\models\GkyWeMenu::findAll(['pid'=>'0']);
        $listData = [['id'=>'0','name'=>'无']];
        $listData = array_merge($listData,$menus);
        echo $form->field($model, 'pid')
            ->dropDownList(
                ArrayHelper::map($listData,'id','name'),
                ['prompt' => '请选择一级菜单']
            )
            ->label('一级菜单 （如果是一级菜单，选择“无”即可）')
    ?>

    <?= $form->field($model, 'name')->textInput(['maxlength' => true])->label('* 菜单名 （可创建最多 3 个一级菜单，每个一级菜单下可创建最多 5 个二级菜单。编辑中的菜单不会马上被用户看') ?>

    <?= $form->field($model, 'sort')
        ->dropDownList(
            [1,2,3,4,5],
            ['prompt' => '请选择排序'])
        ->label('排序号 （数值越小越靠前）')
    ?>

    <?php
    $menuTypes = \app\models\GkyWeMenuType::find()->all();
    echo $form->field($model, 'type')
        ->dropDownList(
            ArrayHelper::map($menuTypes,'id','name'),
            ['prompt' => '请选择类型']
        )
        ->label('类型')
    ?>

    <?= $form->field($model, 'key')->textInput(['maxlength' => true])->label('关联关键词') ?>

    <?= $form->field($model, 'url')->textInput(['maxlength' => true])->label('跳转的URL地址') ?>

    <div class="form-group">
        <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>

<script type="text/javascript">

    $('.field-wechatmenu-key').hide();
    $('.field-wechatmenu-url').hide();

    $('#wechatmenu-type').on('change',function(){
        if($(this).val() == 2){
            $('.field-wechatmenu-key').hide();
            $('.field-wechatmenu-url').show();
        }else{
            $('.field-wechatmenu-key').show();
            $('.field-wechatmenu-url').hide();
        }
    });

</script>
